package com.example.dg.controller;

import cn.hutool.core.io.FileUtil;
import cn.hutool.extra.mail.MailUtil;
import com.example.dg.entity.Entity;
import com.example.dg.service.DgServive;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

@RestController
@RequestMapping("/Dg")
public class DgController {
    @Autowired
    DgServive dgServive;

    /**显示*/
    @PostMapping("/search")
    public List<Entity> Students(@RequestBody Entity entity){
        System.out.println(dgServive.getAllDg(entity));
//        emo();
        return dgServive.getAllDg(entity);
    }
//    public static void emo(){
//        String emo = MailUtil.send("1320153843@qq.com","smiiiiiile!","<h1>章若楠，你好！</h1>"+new Date(),true, FileUtil.file("D:\\AG\\img\\zrn.jpg"));
//        System.out.println(emo);
//        for (int i = 0; i<1; i++){
//            System.out.println(emo);
//        }
//    }

    /**根据id来获取蛋糕信息*/
    @GetMapping("/{id}")
    public Entity getDgById(@PathVariable String id){
        System.out.print(dgServive.getDgById(id));
        return dgServive.getDgById(id);
    }

    /**添加*/
    @PostMapping("")
    public int getAdd(@RequestBody Entity entity){
        return dgServive.Add(entity);
    }

}
